app.controller('redUserListPageCtrl',
    function($ionicBackdrop, $ionicConfig,$rootScope,$interval,$myconfig, $http,$scope, $state, $ionicSideMenuDelegate, $ionicHistory, $ionicPopup, BthSevice, PopupService,$stateParams) {

    // $scope.userMes = JSON.parse(localStorage.getItem('user'));
    $scope.packId = $stateParams.id;

    //分页请求预置限制
    $scope.redpacketlogIf = {
        hasmore_redpacketlog : false,
        page: 1,
        limit: 10
    }

    //预置显示数据空数组
    $scope.redpacketlogData = [];
    //请求红包活动列表
    $scope.redpacketlog = function(id){
        $http.get($myconfig.api.base_host + '/redpacketlogs/totle_list?redpacket_id=' + id +'&page=' + $scope.redpacketlogIf.page + '&limit=' + $scope.redpacketlogIf.limit)
        .then(function(res){
            // var tel = "18827768782";
            var reg = /^(\d{3})\d{4}(\d{4})$/;
            // tel = tel.replace(reg, "$1****$2");
            for(var i = 0;i<res.data.data.length;i++){
                res.data.data[i].mobile = res.data.data[i].mobile.replace(reg,"$1****$2");
            }
            // 判断请求下的数据的条数
             if (res.data.data.length < 10) {
                    // 如果请求下的数据不足十条，则不进行下次请求
                    $scope.redpacketlogIf.hasmore_redpacketlog = true;
                    // 如果请求的数据大于0，则将数据拼接至原有数据之后
                    if (res.data.data.length > 0) {
                        //数据拼接
                        $scope.redpacketlogData = $scope.redpacketlogData.concat(res.data.data);
                    }
                        // console.log(res.data.data);
                    return;
                }
            // console.log(res.data.data);
            $scope.redpacketlogData = $scope.redpacketlogData.concat(res.data.data);
            $scope.redpacketlogIf.page += 1;
            $scope.$broadcast('scroll.infiniteScrollComplete');
        })
    };

    if($scope.packId){
        $scope.redpacketlog($scope.packId);
    }
    $scope.$on('$ionicView.enter', function(){

        $ionicConfig.views.swipeBackEnabled(false);

    });

});
